<?php

namespace app\hotback\logic;
use AlipayConfig;
use AlipayFundTransUniTransferRequest;
use AopCertClient;
use app\common\basics\Logic;
use think\Db;

require_once ROOT_PATH.'public/aop/AopClient.php';
require_once ROOT_PATH.'public/aop/AopCertClient.php';
require_once ROOT_PATH.'public/aop/AopCertification.php';
require_once ROOT_PATH.'public/aop/AlipayConfig.php';
require_once ROOT_PATH.'public/aop/request/AlipayFundTransUniTransferRequest.php';
/**
 * 工作台统计
 * Class StatLogic
 * @package app\admin\logic\index
 */
class ZzLogic extends Logic
{
    public static function zz_zfb(){


        $privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCLG1CVwOQ6mK3h34IDwfW5sDhxNuT+sZTiqBt5oE17uQdp+Id5S/bjkoztc6sq00ASLJCSEUUXDCd+VSnlfuyoB9TnXnL2Rh6GCFuqjv/Wv6pwRRBCsx6P2VaChSnDXRNsmXbHb7nfWrjc6cdwQNQQzrWL9gR01SFs9SHmuplN0UNAiwN0iTiPFtuhszlRO8TX40Adv4+eFPGCA0Hl8BGTGd2olfcpJM+gkmrPd+9TdCEeiNsfAmxOnCOKagbRTjbSNLKXGGLmR3MHMcyPsUPqAw/NYIqgbjTNlbsXrr2OW6nALAfiKNzIRbnbf4uv+luhv3zJ+iq5fKvf43J6JgFXAgMBAAECggEAUlJX3kfIyOSSApnC13ZxdPJUdKuH2TI+aeQSXmf/criNKqlpgt7xvLt9qwhIw49A24CEDe0qdfk7ZggAQ1BZvRblaAb9AcF9TtSjasw1m2DR/J7igJZ//6EfER69GGB8nkgzgtMbrJKD1DiFTmkPFuM9jRaKjJmUrmZjKahEEUhiPgOnWsYd2UKAT592HkqsIKpSkAxPw/fWh0zKdey/yJz+ZNNK9kc+IIJp8MLvpDW2LIxqN3BM3618hsF2kIKqnIN2DYkHXdRbr8I9j8O1eiEx1QUXUgsYzSMvivTS3jJ1go2BU4BMKeRWRfAZItIBS13LUiASC5expNe6BYh0AQKBgQDmKr9OzDQxXbllNMeJKN35C0HMGJrpvtzfmKy6ThnZz+yc6mTAQ0ru+s6a7ZyJECsYKSjLVaOqpzY90rUBIPVzmQ27BJ3pzyPwwmtvazWMP2ztxWmDubVmvFgPJw6Mb6XxJKKvLmVNtOx9snF+3hOpyMM1gYoIsDOEqZoYqbpc7QKBgQCauC+T7bwnF2Hw0GhFS2yDRpF8FWokEyEVS/TUCYgiSb7zAGYgcftTtjyPwXSIOOZuinrynNazm5tcgGFldvBzmSo5XGlv9m16ozRSdm2+BGrA7xnMB3H5az9iIWOV9UZ9HaD6R5uj61GhRHi5DS5Fgi36FQk9oRbmmevJkXXS0wKBgHVtgcUV8drt0lSMJPEZZIZW8+7I7uAqfE2nexhiGFZD+pfkDhr5OhXK5/WrHJ3hHdtpxGJZAvNh9A5+ndJBmnirsZGkvVw4TkHbLyzdKaiwA0cb3MVTzfToSpUQfB+yJpts8YMmzJBkqfNHQxhS/P02bEG0IVRlcSNR1EiY73fRAoGAW03EbgTGmz8WQjmKvxHiiJnVcydkCsPrKxk28wZo+usQL3EV06HQEjeiB6e/cEA75BH+ujvKDBYRGgZ885a8EUva+hzJ8BO5ybyUPPG8k30hzpeLXrcqEGm07uELVsx2+5DHlcs6UwKkmonAwFvB6a0IGuPdHyx4Sj+dQMeBg5cCgYEAq7Vir3tUcnATVG6vBhiG0frBpxHdAP4rXBUYFNztjavs7ReS1rN7pOJ0siRxr1zd8XRT81pyMmlJyfK0KxZWjRq6JMN+kgNSm8zS3izviOD3C/7K8C6Noq2YkiGfSIT7aFU/19T3VcFDQx01BUlwkrygoKrcim/4AB/PPXVz60Q=";
        $alipayConfig = new AlipayConfig();
        $alipayConfig->setPrivateKey($privateKey);
        $alipayConfig->setServerUrl("https://openapi.alipay.com/gateway.do");
        $alipayConfig->setAppId("2021003176624509");
        $alipayConfig->setCharset("UTF-8");
        $alipayConfig->setSignType("RSA2");
        $alipayConfig->setEncryptKey("");
        $alipayConfig->setFormat("json");
        $alipayConfig->setAppCertPath(ROOT_PATH."public/all_key/appCertPublicKey_2021003176624509.crt");
        $alipayConfig->setAlipayPublicCertPath(ROOT_PATH."public/all_key/alipayCertPublicKey_RSA2.crt");
        $alipayConfig->setRootCertPath(ROOT_PATH."public/all_key/alipayRootCert.crt");
        $alipayClient = new AopCertClient($alipayConfig);
        $alipayClient->isCheckAlipayPublicCert = true;
        $request = new AlipayFundTransUniTransferRequest();
        $data['out_biz_no'] = date('Ymd',time()).time().rand(10000,99999);
        $data['trans_amount'] = 0.1;
        $data['product_code'] = 'TRANS_ACCOUNT_NO_PWD';
        $data['biz_scene'] = 'DIRECT_TRANSFER';
        $data['payee_info']['identity'] = '150355141951';
        $data['payee_info']['identity_type'] = 'ALIPAY_LOGON_ID';
        $data['payee_info']['name'] = '鹿坤';
        $data['order_title'] = '技师提现';
        $data['remark'] = '技师提现转账';
        $data['business_params']['payer_show_name_use_alias'] = true;
        $send = json_encode($data);
//        dump($send);die;
//        $send = mb_convert_encoding($send,"UTF8","UTF-8");
        $request->setBizContent($send);

        $responseResult = $alipayClient->execute($request);

        $responseApiName = str_replace(".","_",$request->getApiMethodName())."_response";
        $response = $responseResult->$responseApiName;
        dump($data);
        dump($response);die;
        if(!empty($response->code)&&$response->code==10000){
            echo("调用成功");
        }
        else{
            echo("调用失败");
        }
    }

    public static function techn_zfb($money,$mobile,$name,$title = '技师提现',$reason = '技师提现转账'){


        $privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCLG1CVwOQ6mK3h34IDwfW5sDhxNuT+sZTiqBt5oE17uQdp+Id5S/bjkoztc6sq00ASLJCSEUUXDCd+VSnlfuyoB9TnXnL2Rh6GCFuqjv/Wv6pwRRBCsx6P2VaChSnDXRNsmXbHb7nfWrjc6cdwQNQQzrWL9gR01SFs9SHmuplN0UNAiwN0iTiPFtuhszlRO8TX40Adv4+eFPGCA0Hl8BGTGd2olfcpJM+gkmrPd+9TdCEeiNsfAmxOnCOKagbRTjbSNLKXGGLmR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qEGm07uELVsx2+5DHlcs6UwKkmonAwFvB6a0IGuPdHyx4Sj+dQMeBg5cCgYEAq7Vir3tUcnATVG6vBhiG0frBpxHdAP4rXBUYFNztjavs7ReS1rN7pOJ0siRxr1zd8XRT81pyMmlJyfK0KxZWjRq6JMN+kgNSm8zS3izviOD3C/7K8C6Noq2YkiGfSIT7aFU/19T3VcFDQx01BUlwkrygoKrcim/4AB/PPXVz60Q=";
        $alipayConfig = new AlipayConfig();
        $alipayConfig->setPrivateKey($privateKey);
        $alipayConfig->setServerUrl("https://openapi.alipay.com/gateway.do");
        $alipayConfig->setAppId("2021003176624509");
        $alipayConfig->setCharset("UTF-8");
        $alipayConfig->setSignType("RSA2");
        $alipayConfig->setEncryptKey("");
        $alipayConfig->setFormat("json");
        $alipayConfig->setAppCertPath(ROOT_PATH."public/all_key/appCertPublicKey_2021003176624509.crt");
        $alipayConfig->setAlipayPublicCertPath(ROOT_PATH."public/all_key/alipayCertPublicKey_RSA2.crt");
        $alipayConfig->setRootCertPath(ROOT_PATH."public/all_key/alipayRootCert.crt");
        $alipayClient = new AopCertClient($alipayConfig);
        $alipayClient->isCheckAlipayPublicCert = true;
        $request = new AlipayFundTransUniTransferRequest();
        $data['out_biz_no'] = date('Ymd',time()).time().rand(10000,99999);
        $data['trans_amount'] = $money;
        $data['product_code'] = 'TRANS_ACCOUNT_NO_PWD';
        $data['biz_scene'] = 'DIRECT_TRANSFER';
        $data['payee_info']['identity'] = $mobile;
        $data['payee_info']['identity_type'] = 'ALIPAY_LOGON_ID';
        $data['payee_info']['name'] = $name;
        $data['order_title'] = $title;
        $data['remark'] = $reason;
        $data['business_params']['payer_show_name_use_alias'] = true;
        $send = json_encode($data);
//        dump($send);die;
//        $send = mb_convert_encoding($send,"UTF8","UTF-8");
        $request->setBizContent($send);

        $responseResult = $alipayClient->execute($request);

        $responseApiName = str_replace(".","_",$request->getApiMethodName())."_response";
        $response = $responseResult->$responseApiName;

        if(!empty($response->code)&&$response->code==10000){
            $return = [
                'code'=>0,
                'msg'=>$response->msg,
                'out_biz_no'=>$response->out_biz_no,
            ];
            return $return;
        }
        else{
            $return = [
                'code'=>-1,
                'msg'=>$response->sub_msg,
            ];
            return $return;
        }
    }


}